class Hero {
    hp = 0
    minAp = 0  //最小攻击力
    maxAp = 0  //最大攻击力
    dodgeRate = 0  //闪避
    strikeRate = 0  //暴击
    name = ''

    static heroCount = 0
    static createHero(
        name, hp, maxAp, minAp, strikeRate, dodgeRate
    ) {
        const hero = new Hero()
        hero.id = 'h' + (++this.heroCount)
        hero.name = name
        hero.hp = hp
        hero.maxAp = maxAp
        hero.minAp = minAp
        hero.strikeRate = strikeRate
        hero.dodgeRate = dodgeRate
        return hero
    }
    static attackLog(h1, h2, ap, static, dodge) {

        return `<div id="vs"${strike ? 'strike' : ''}${dodge ? 'dodge' : ''}>
        <span class='${h1.id}'>${h1.name}</span>
        ${strike ? `奋力一击产生${ap * 2}伤害` : `发起进攻产生${ap}伤害`},
        ${dodge ? `被<span class='${h2.id}'>${h2.name}</span> 闪开了` : ``
            }<span class='${h2.id}'>${h2.name}</span>还有${h2.hp}血量
        </div>`
    }

    attack(hero) {
        const ap =
            Math.floor(Math.random() * (this.maxAp - this.minAp)) + this.minAp//攻击力

        const strike = Math.random() < this.strikeRate
        const dodge = Math.random() < hero.dodgeRate
        hero.hp = hero.hp - (dodge ? 0 : (strike ? ap * 2 : ap))
        return Hero.attackLog(
            this, hero, ap, strike, dodge
        )
    }
}